﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Diagnostics;

namespace SimpleIR
{
	/// <summary>
	/// Class representing pointers.
	/// These may be stored in the heap, can never be to the interior of an object or struct and can never point to fixed locations.
	/// </summary>
	public sealed class IRPtrType : IRType
	{
		public readonly IRClassType PtrTargetType;

		public readonly bool IsNullPointer;

		public IRPtrType(int typeid, string tnamespace, string tbasename, TypeQualifiers tqual, IRClassType trgt)
			: base(typeid, tnamespace, tbasename, tqual)
		{
			this.PtrTargetType = trgt;
			this.IsNullPointer = false;
		}

		public static IRPtrType MakeSpecialNullPtr(int typeid)
		{ return new IRPtrType(typeid); }

		//Only for making the special null pointer
		private IRPtrType(int typeid)
			: base(typeid, null, "null", TypeQualifiers.PublicTag | TypeQualifiers.BuiltinTag)
		{
			this.PtrTargetType = null;
			this.IsNullPointer = true;
		}
	}

	/// <summary>
	/// Class representing references.
	/// These may NOT be stored in the heap, locations of this type can NEVER BE NULL or may ONLY be assigned to ONCE.
	/// However, they can be to the interior of an object or struct and can point to fixed locations.
	/// </summary>
	public sealed class IRReferenceType : IRType
	{
		/// <summary>
		/// The type that the reference is refering to.
		/// </summary>
		public readonly IRType ReferenceTargetType;

		public IRReferenceType(int typeid, string tnamespace, string tbasename, TypeQualifiers tqual, IRType trgt)
			: base(typeid, tnamespace, tbasename, tqual)
		{ this.ReferenceTargetType = trgt; }
	}
}
